package com.jswlw.controller.api.wrapper;

import com.alibaba.fastjson.JSON;
import com.jswlw.common.ResponseStatus;
import com.jswlw.controller.api.resp.BillSetListResponse;
import com.jswlw.entity.biz.BillSet;
import com.jswlw.entity.biz.DevInfo;
import com.jswlw.entity.biz.DevType;
import com.jswlw.service.biz.BillSetService;
import com.jswlw.service.biz.DevInfoService;
import com.jswlw.service.biz.DevTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Slf4j
@Component
public class BillSetWrapper {
    @Autowired
    BillSetService billSetService;
    @Autowired
    DevInfoService devInfoService;
    @Autowired
    DevTypeService devTypeService;

    public BillSetListResponse billSetList(String devId) {
        DevInfo devInfo = devInfoService.find4Id(devId);
        BillSetListResponse response = new BillSetListResponse();
        DevType devType = devTypeService.find4Id(devInfo.getDevTypeId());
        List<BillSet> list = devType.getBillSetList();
        List<BillSetListResponse.BillSetListData> data = new ArrayList<>();
        list.forEach(billSet -> {
            if (devInfo.getDevStatus().equals(1)) {
                data.add(BillSetListResponse.BillSetListData.builder()
                        .id(billSet.getId())
                        .name(billSet.getName())
                        .num(billSet.getNum())
                        .price(billSet.getPrice())
                        .billingModel(billSet.getBillingModel())
                        .build());
            } else {
                if (devInfo.getBillTypeId().equals(billSet.getBillingModel())) {
                    data.add(BillSetListResponse.BillSetListData.builder()
                            .id(billSet.getId())
                            .name(billSet.getName())
                            .num(billSet.getNum())
                            .price(billSet.getPrice())
                            .billingModel(billSet.getBillingModel())
                            .build());
                }
            }

        });
        response.setData(data);
        response.setCode(ResponseStatus.SUCCESS.getCode());
        response.setMsg(ResponseStatus.SUCCESS.getMsg());
        log.info("套餐信息:" + JSON.toJSONString(data));
        return response;
    }
}
